Repository navigation
Cache /_astro/ files for a day instead of a year - #49
Merged
Merged
Conversation
public/_headers gives /_astro/* a year of immutable caching, and Cloudflare adds it to the 404 for a missing file too. Right after a deploy, a page can ask for a new stylesheet from an edge that still serves the previous version; the browser could then keep that 404 for a year. Run the Worker first for /_astro/* as well as /images/*. It passes every response on as the assets serve it, except a 404, which gets Cache-Control: no-store. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013MdjUbV3zudUd8ZBxydwBu
|
Preview: https://pr-49-meaningfool.josselin-perrus.workers.dev Built from c656779 with the latest content. The link stays the same and shows the latest push. Search engines are asked not to index it. |
Running the Worker for every /_astro/ request was out of proportion with the problem: it counts each of those requests toward the Worker's limits. Undo that, and instead shorten the caching public/_headers gives /_astro/* from a year (immutable) to a day. A 404 served in the seconds after a deploy then stays in a browser for a day at most, and reloading the page in Firefox or Safari checks it again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013MdjUbV3zudUd8ZBxydwBu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
public/_headersgives/_astro/*Cache-Control: public, max-age=31536000, immutable. Cloudflare sends that header with the 404 for a missing file too:Right after #48 deployed, the first load of
/apps/one-light-day/got its new stylesheet back as a 404 page, probably from a Cloudflare server still on the previous version. This can happen in the seconds after any deploy that adds files to/_astro/: a new app, a style change, or a new article with images. Only the visitor's browser keeps the 404, not Cloudflare, but it can keep it for a year.Change
/_astro/*now getsCache-Control: public, max-age=86400, so browsers keep these files for a day.immutable, reloading the page in Firefox or Safari checks the files again, which fixes it sooner.AGENTS.mdand the comment inpublic/_headersexplain why it's a day.The first commit, since undone: it ran the Worker for every
/_astro/*request so it could sendno-storeon 404s only. That kept the year-long caching, but every request for these files would have counted toward the Worker's daily limit on the Free plan, which was out of proportion with how rare the problem is. The second commit restoreswrangler.jsoncandworker/index.jsexactly as they are onmain.Checks
Build:
diff -ragainst a build ofmainwith the same content shows onlydist/_headers, which Cloudflare reads but never serves, and theGenerated:timestamps inllms.txtandllms-full.txt. Every page is identical.Headers, compared with
mainunderwrangler dev: only/_astro/responses changed. These went frompublic, max-age=31536000, immutabletopublic, max-age=86400:If-None-Match304/_astro/Pages, redirects,
/rss.xml, video byte ranges and the other 404s are unchanged.bun run test:documents: 12 passed.To check on the preview:
This should return 404 with
cache-control: public, max-age=86400.🤖 Generated with Claude Code
https://claude.ai/code/session_013MdjUbV3zudUd8ZBxydwBu